<?php

namespace App\Services\Game\Config;

use App\Services\Service;
use App\Services\Traits\DatabaseMysql;
use App\Models\Game\Config\Currency;

class CurrencyService extends Service
{
    use DatabaseMysql;

    /**
     * 获取数据列表
     *
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Database\Eloquent\Collection[]|int[]
     */
    public function getList($request)
    {
        $query = Currency::query();

        // 筛选【类型】
        $this->makeWhereParam($request, 'type', $query);
        // 筛选【状态】
        $this->makeWhereParam($request, 'status', $query);
        // 筛选【时间】
        $this->makeWhereParamDatetime($request, $query);
        // 筛选【搜索】
        $this->makeWhereParamLike(
            $request, 'keyword', $query,
            $request->input('keyword_column'), false
        );

        // 数据条数
        $total = (clone $query)->count();
        // 排序分页
        $this->makeOrderParam($request, $query)->makePaginationParam($request, $query);
        // 查询数据
        $collection = $query->get();

        return [
            $collection,
            $total
        ];
    }
}
